﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Fluent.IO;
using Prototipo.CMS.Models;

namespace Prototipo.CMS.Areas.Admin.Controllers
{
    public class DashboardController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Conf = new Configuration(Server.MapPath("~/"));
            ViewBag.Themes = new List<string>();

            foreach (var dir in Path.Get(Server.MapPath("~/Themes")).Directories())
            {
                ViewBag.Themes.Add(dir.FileName);
            }

            return View();
        }

        [HttpPost]
        public JsonResult ChangeTheme(string themeName)
        {
            try
            {
                var configuration = new Configuration(Server.MapPath("~/"));
                configuration.Theme.Name = themeName;

                configuration.Save();
                return Json(new { result = "success" });
            }
            catch (Exception)
            {
                return Json(new {result = "error"});
            }
        }

    }
}
